<?
/*
 * scrumbrella - Scrum board.
 *
 * Copyright (C) 2009  Gustavo N. Borgoni <gborgoni@voicemedia.com.ar>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

require_once("layout_config.php");
require_once("PHPTAL.php");

include("include/permission.php");
include("include/project.php");
include("include/html_utils.php");
include("layout_config.php");

// Check for user logged in
$user_id = permission_redirect_user("index.php");
	// Set tab selected
	$_SESSION['selected'] = 2;

	if ($_SERVER['REQUEST_METHOD'] == "POST") {
		$_SESSION['project'] = $_REQUEST['project'];
	}

	// Load the template
	$temp = new PHPTAL('templates/resources.xhtml');

	$temp->theme  = 'default';
	$temp->title  = _("Resources administration");
	$temp->bt_new = _("Add");
	$temp->msg    = 0;
	$temp->id     = $_SESSION['project'];
	$temp->role   = _("Role");
	$temp->name   = _("User name");
	$temp->alias  = _("Alias");
	$temp->email  = _("Email");

	// Bar
	$temp->prj_title = _("Project");
	$temp->bt_select = _("Select");
	$temp->err_select = _("Please select a project");
	$projects = html_select_projectbyuser($user_id, $_SESSION['project']);
	$temp->projects = $projects;

	$members = project_get_members($_SESSION['project']);
	if (!$members) {
		$temp->pbacklog = 0;
		$temp->msg      = 1;
		$temp->message  = _("This project have not members");
	} else {
		$i=0;
		foreach ($members AS $member) {
			if ($class == 'project_item_cebra') {
				$class = 'project_item';
			} else {
				$class = 'project_item_cebra';
			}

			$usr[$i]['class'] = $class;
			$usr[$i]['role']  = $member['role'];
			$usr[$i]['alias'] = $member['alias'];
			$usr[$i]['email'] = $member['email'];
			$usr[$i]['name']  = $member['name']." ".$member['lastname'];
			$i++;
		}
		$temp->members = $usr;
	}

	try 
	{
		echo $temp->execute();
	}

	catch(Exception $e)
	{
		echo $e;
	}
?>
